package hhj.demo.lbs;

public class LBSUtils {
    public static void main(String[] args) {
        double lng1 = 116.404;
        double lat1 = 39.915;
        double lng2 = 116.404719;
        double lat2 = 39.919284;
        
        double result = getDistance(lng1, lat1, lng2, lat2);
        System.out.println(result);
    }

    public static double getDistance(double lng1, double lat1, double lng2, double lat2) {
        double pk = 180 / Math.PI;
        double a1 = lat1 / pk;
        double a2 = lng1 / pk;
        double b1 = lat2 / pk;
        double b2 = lng2 / pk;
        double t1 = Math.cos(a1) * Math.cos(a2) * Math.cos(b1) * Math.cos(b2);
        double t2 = Math.cos(a1) * Math.sin(a2) * Math.cos(b1) * Math.sin(b2);
        double t3 = Math.sin(a1) * Math.sin(b1);
        double tt = Math.acos(t1 + t2 + t3);
        
        return 6370996.81 * tt;
    }
}
